package com.dlyk.service.impl;

import com.dlyk.DlykServerApplication;
import com.dlyk.constant.Constants;
import com.dlyk.mapper.DicValueMapper;
import com.dlyk.model.DicValue;
import com.dlyk.result.DicEnum;
import com.dlyk.service.DicValueService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DicValueServiceImpl implements DicValueService {

    @Resource
    private DicValueMapper dicValueMapper;

    /**
     * 查询跟踪方式字典数据
     */
    @Override
    public List<DicValue> getNoteWay() {

        // 从内存中获取字典数据（跟踪方式的字典数据）
        List<DicValue> dicValueList = (List<DicValue>) DlykServerApplication.cacheMap.get(DicEnum.NOTE_WAY.getCode());

        return dicValueList;
    }

    /**
     * 查询字典数据列表（分页查询）
     */
    @Override
    public PageInfo<DicValue> getDicValueListByPage(Integer current, String typeCode) {

        // 1、设置PageHelper
        PageHelper.startPage(current, Constants.PAGE_SIZE);

        // 2、查询
        List<DicValue> dicValueList = dicValueMapper.selectDicValueListByPage(typeCode);

        // 3、封装分页数据到PageInfo
        PageInfo<DicValue> dicTypePageInfo = new PageInfo<>(dicValueList);

        return dicTypePageInfo;
    }

    /**
     * 录入字典数据
     */
    @Override
    public int addDicValue(DicValue dicValue) {
        return dicValueMapper.insertSelective(dicValue);
    }

    /**
     * 编辑字典数据
     */
    @Override
    public int editDicValue(DicValue dicValue) {
        return dicValueMapper.updateByPrimaryKeySelective(dicValue);
    }

    /**
     * 删除字典数据
     */
    @Override
    public int removeDicValueById(Integer id) {
        return dicValueMapper.deleteByPrimaryKey(id);
    }

    /**
     * 查询是否贷款字典数据
     */
    @Override
    public List<DicValue> getNeedLoan() {

        // 从内存中获取字典数据（是否贷款的字典数据）
        List<DicValue> dicValueList = (List<DicValue>) DlykServerApplication.cacheMap.get(DicEnum.NEED_LOAN.getCode());

        return dicValueList;
    }

    /**
     * 获取交易阶段下拉选项
     */
    @Override
    public List<DicValue> getStage() {

        // 从内存中获取字典数据（交易阶段的字典数据）

        List<DicValue> dicValueList = (List<DicValue>) DlykServerApplication.cacheMap.get(DicEnum.STAGE.getCode());

        return dicValueList;
    }

}

